#ifndef _FRAMEALLOCATOR_H_
#define _FRAMEALLOCATOR_H_

#define FRAMES_MAX		1024 * 1024
#define INDEX_FROM_BIT(a)	(a / 32)
#define OFFSET_FROM_BIT(a)	(a % 32)

#include <types.h>
#include <Spinlock.h>

class FrameAllocator {
public:
	static void Init();
	static dword Alloc(dword start, dword n);
	static void Free(dword start, dword n);
	static void MarkFrames(dword start, dword frames, bool used);
	
private:
	static void set(dword frame);
	static void clear(dword frame);
	static bool test(dword frame);
	static dword FirstFree(dword start);

	static dword bitmap[FRAMES_MAX / 32];
	static Spinlock Lock;
};

#endif
